Calculate the sum of all digits of the base to the specified powerΒΆ
Calculate the sum of all digits of the base to the specified power.
Test Data:
If power_base_sum(2, 100)
Expected output:
115
def power_base_sum(base, power):
# str() to make 'int' object iterable
return sum([int(i) for i in str(pow(base, power))])
# test
print(power_base_sum(2, 100))
print(power_base_sum(8, 10))
Output:
115
37